<%#
kind: PXEGrub
name: PXEGrub global default
model: ProvisioningTemplate
%>
<%# Used to boot unknown hosts, do not associate or change the name. %>
<%
  # Grub1 only supports numeric default statement, this allows conversion to number. First define
  # array of directories we will search for EFI booloaders:
  paths = ["fedora", "redhat", "centos", "debian", "ubuntu", "sles", "opensuse", "Microsoft", "EFI"]
  # Add remaining entries to it and use this to convert to number:
  items = paths.push("local_chain_hd0", "discovery")
  # Read default setting but since "local" is missing, use the first path available.
  default_setting = global_setting("default_pxe_item_global", paths.first)
  default_setting = paths.first if default_setting == 'local'
  default_item = items.index(default_setting) || 0
%>
default=<%= default_item %>
timeout=20

<%= snippet "pxegrub_chainload", variables: {paths: paths} %>

<%= snippet "pxegrub_discovery" %>

<% unless @profiles.nil? -%>
<% for profile in @profiles
  url = default_template_url(profile[:template], profile[:hostgroup])
  case profile[:pxe_type]
  when 'kickstart'
    append = "ks=#{url} ksdevice=bootif network kssendmac ks.sendmac inst.ks.sendmac"
  when 'preseed'
    locale = profile[:hostgroup].params['lang'] || 'en_US'
    append = "interface=auto url=#{url} ramdisk_size=10800 root=/dev/rd/0 rw auto hostname=unassigned-hostname locale=#{locale} console-setup/ask_detect=false console-setup/layout=USA console-setup/variant=USA"
  else
    raise("PXE type #{profile[:pxe_type]} not supported by template #{template_name}")
  end %>
title <%= "#{profile[:hostgroup]} - #{profile[:template]}" %>
  kernel <%= profile[:kernel] %> <%= append %>
  initrd <%= profile[:initrd] %>
<% end %>
<% end -%>
